home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / include / utility / pack.h < prev    next >
C/C++ Source or Header  |  1996-09-10  |  7KB  |  177 lines

  1. #ifndef UTILITY_PACK_H
  2. #define UTILITY_PACK_H 1
  3. /*
  4. ** pack.h for ACE Basic
  5. **
  6. ** Note: Translated to ACE by ConvertC2ACE
  7. **       @ MapMeadow Software, Nils Sjoholm
  8. **
  9. **
  10. ** Date: 09/03/95
  11. **
  12. **
  13. */
  14.  
  15.  
  16. /*****************************************************************************/
  17.  
  18.  
  19. #ifndef EXEC_TYPES_H
  20. #include <exec/types.h>
  21. #endif
  22.  
  23. #ifndef UTILITY_TAGITEM_H
  24. #include <utility/tagitem.h>
  25. #endif
  26.  
  27.  
  28. /*****************************************************************************/
  29.  
  30.  
  31. /* PackTable definition:
  32.  *
  33.  * The PackTable is a simple array of LONGWORDS that are evaluated by
  34.  * PackStructureTags() and UnpackStructureTags().
  35.  *
  36.  * The table contains compressed information such as the tag offset from
  37.  * the base tag. The tag offset has a limited range so the base tag is
  38.  * defined in the first longword.
  39.  *
  40.  * After the first longword,  the fields look as follows:
  41.  *
  42.  *  +--------- 1 = signed,  0 = unsigned (for bits,  1=inverted boolean)
  43.  *  |
  44.  *  OR  +------ 00 = Pack/Unpack,  10 = Pack,  01 = Unpack,  11 = special
  45.  *  OR / \
  46.  *  OR | OR  +-- 00 = Byte,  01 = SHORTINT,  10 = LONGINT,  11 = Bit
  47.  *  OR | OR / \
  48.  *  OR | OR | OR /----- For bit operations: 1 = TAG_EXISTS is TRUE
  49.  *  OR | OR | OR |
  50.  *  OR | OR | OR | /-------------------- Tag offset from base tag value
  51.  *  OR | OR | OR | OR             \
  52.  *  m n n o o p q q q q q q q q q q r r r s s s s s s s s s s s s s
  53.  *                  \   OR |           |
  54.  *  Bit offset (for bit operations) ----/ OR           |
  55.  *                        \               |
  56.  *  Offset into data structure -----------------------------------/
  57.  *
  58.  * A -1 longword signifies that the next longword will be a new base tag
  59.  *
  60.  * A 0 longword signifies that it is the end of the pack table.
  61.  *
  62.  * What this implies is that there are only 13-bits of address offset
  63.  * and 10 bits for tag offsets from the base tag.  For most uses this
  64.  * should be enough,  but when this is not,  either multiple pack tables
  65.  * or a pack table with extra base tags would be able to do the trick.
  66.  * The goal here was to make the tables small and yet flexible enough to
  67.  * handle most cases.
  68.  */
  69.  
  70. #define PSTB_SIGNED 31
  71. #define PSTB_UNPACK 30    /* Note that these are active low... */
  72. #define PSTB_PACK   29    /* Note that these are active low... */
  73. #define PSTB_EXISTS 26    /* Tag exists bit true flag hack...  */
  74.  
  75. #define PSTF_SIGNED (2147483648&)
  76. #define PSTF_UNPACK (1073741824&)
  77. #define PSTF_PACK   (536870912&)
  78.  
  79. #define PSTF_EXISTS (67108864&)
  80.  
  81.  
  82. /*****************************************************************************/
  83.  
  84.  
  85. #define PKCTRL_PACKUNPACK &H00000000
  86. #define PKCTRL_PACKONLY   &H40000000
  87. #define PKCTRL_UNPACKONLY &H20000000
  88.  
  89. #define PKCTRL_BYTE   &H80000000
  90. #define PKCTRL_WORD   &H88000000
  91. #define PKCTRL_LONG   &H90000000
  92.  
  93. #define PKCTRL_UBYTE      &H00000000
  94. #define PKCTRL_UWORD      &H08000000
  95. #define PKCTRL_ULONG      &H10000000
  96.  
  97. #define PKCTRL_BIT    &H18000000
  98. #define PKCTRL_FLIPBIT    &H98000000
  99.  
  100.  
  101. /*****************************************************************************/
  102.  
  103.  
  104. /* Macros used by the next batch of macros below. Normally,  you don't use
  105.  * this batch directly. Then again,  some folks are wierd
  106.  */
  107. /*
  108. #define PK_BITNUM1(flg) ((flg) == &H01 ? 0 : (flg) == &H02 ? 1 : (flg) == &H04 ? 2 : (flg) == &H08 ? 3 : (flg) == &H10 ? 4 : (flg) == &H20 ? 5 : (flg) == &H40 ? 6 : 7)
  109. #define PK_BITNUM2(flg) ((flg < &H100 ? PK_BITNUM1(flg) : 8+PK_BITNUM1(flg >> 8)))
  110. #define PK_BITNUM(flg) ((flg < &H10000 ? PK_BITNUM2(flg) : 16+PK_BITNUM2(flg >> 16)))
  111. #define PK_WORDOFFSET(flg) ((flg) < &H100 ? 1 : 0)
  112. #define PK_LONGOFFSET(flg) ((flg) < &H100  ? 3 : (flg) < &H10000 ? 2 : (flg) < &H1000000 ? 1 : 0)
  113. #define PK_CALCOFFSET(type, field) ((LONGINT)(&((STRUCT type *)0)->field))
  114. */
  115.  
  116. /*****************************************************************************/
  117.  
  118.  
  119. /* Some handy dandy macros to easily create pack tables
  120.  *
  121.  * Use PACK_STARTTABLE() at the start of a pack table. You pass it the
  122.  * base tag value that will be handled in the following chunk of the pack
  123.  * table.
  124.  *
  125.  * PACK_ENDTABLE() is used to mark the end of a pack table.
  126.  *
  127.  * PACK_NEWOFFSET() lets you change the base tag value used for subsequent
  128.  * entries in the table
  129.  *
  130.  * PACK_ENTRY() lets you define an entry in the pack table. You pass it the
  131.  * base tag value,  the tag of interest,  the type of the structure to use, 
  132.  * the field name in the structure to affect and control bits (combinations of
  133.  * the various PKCTRL_XXX bits)
  134.  *
  135.  * PACK_BYTEBIT() lets you define a bit-control entry in the pack table. You
  136.  * pass it the same data as PACK_ENTRY,  plus the flag bit pattern this tag
  137.  * affects. This macro should be used when the field being affected is byte
  138.  * sized.
  139.  *
  140.  * PACK_WORDBIT() lets you define a bit-control entry in the pack table. You
  141.  * pass it the same data as PACK_ENTRY,  plus the flag bit pattern this tag
  142.  * affects. This macro should be used when the field being affected is SHORTINT
  143.  * sized.
  144.  *
  145.  * PACK_LONGBIT() lets you define a bit-control entry in the pack table. You
  146.  * pass it the same data as PACK_ENTRY,  plus the flag bit pattern this tag
  147.  * affects. This macro should be used when the field being affected is longword
  148.  * sized.
  149.  *
  150.  * EXAMPLE:
  151.  *
  152.  *    LONGINT packTable[] =
  153.  *     
  154.  *     PACK_STARTTABLE(GA_Dummy), 
  155.  *     PACK_ENTRY(GA_Dummy, GA_Left, Gadget, LeftEdge, PKCTRL_WORD|PKCTRL_PACKUNPACK), 
  156.  *     PACK_ENTRY(GA_Dummy, GA_Top, Gadget, TopEdge, PKCTRL_WORD|PKCTRL_PACKUNPACK), 
  157.  *     PACK_ENTRY(GA_Dummy, GA_Width, Gadget, Width, PKCTRL_UWORD|PKCTRL_PACKUNPACK), 
  158.  *     PACK_ENTRY(GA_Dummy, GA_Height, Gadget, Height, PKCTRL_UWORD|PKCTRL_PACKUNPACK), 
  159.  *     PACK_WORDBIT(GA_Dummy, GA_RelVerify, Gadget, Activation, PKCTRL_BIT|PKCTRL_PACKUNPACK, GACT_RELVERIFY)
  160.  *     PACK_ENDTABLE
  161.  *    END STRUCT 
  162.  */
  163. /*
  164. #define PACK_STARTTABLE(tagbase)               (tagbase)
  165. #define PACK_NEWOFFSET(tagbase)            (-1L), (tagbase)
  166. #define PACK_ENDTABLE                      0
  167. #define PACK_ENTRY(67108864&)     (control OR ((tag-tagbase) << 16L) OR PK_CALCOFFSET(type, field))
  168. #define PACK_BYTEBIT(67108864&) (control OR ((tag-tagbase) << 16L) OR PK_CALCOFFSET(type, field) OR (PK_BITNUM(flags) << 13L))
  169. #define PACK_WORDBIT(67108864&) (control OR ((tag-tagbase) << 16L) OR (PK_CALCOFFSET(type, field)+PK_WORDOFFSET(flags)) OR ((PK_BITNUM(flags)&7) << 13L))
  170. #define PACK_LONGBIT(67108864) (control OR ((tag-tagbase) << 16L) OR (PK_CALCOFFSET(type, field)+PK_LONGOFFSET(flags)) OR ((PK_BITNUM(flags)&7) << 13L))
  171. */
  172.  
  173. /*****************************************************************************/
  174.  
  175.  
  176. #endif /* UTILITY_PACK_H */
  177.